Skip to content

feat(aggregator): browse historical AA dataset batches - #7564

Merged
dezren39 merged 9 commits into
mainfrom
queue/12631-3302-aa-batch-versioning
Nov 10, 2026
Merged

dezren39 merged 9 commits into
mainfrom
queue/12631-3302-aa-batch-versioning

Conversation

@dezren39

@dezren39 dezren39 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Summary

AA collector now indexes workbook batches from ainventory.sources, caches batch-scoped payloads, and serves a selected historical version at /aa?batch=<uuid> and /api/aa.json?batch=<uuid>. The selector identifies the active/latest version and downloads use the selected dataset; latest remains the default. Historical query logic avoids the latest-only ranking/threshold views, and carrier duplicates collapse only when semantic fingerprints match.

collector -> batch index + bounded historical cache
live source -> selected cached section
/aa -> selector + batch-aware API and download links

Part of #3302; intentionally does not close it before the requested laptop live verification.

Evidence

  • PM_AGG_FRESHNESS_PORT=15171 bun test test/aa-batches.test.ts test/aa.test.ts — 58 passed.
  • git diff --check — passed.
  • bun run typecheck — changed code passes; blocked by existing test/roadmap-annotations.test.ts:89 kind typing error.
  • Before: /aa and /api/aa.json always served latest only. After: source-level regression test selects a cached historical batch and confirms latest remains the default.

Merge Danger

Door: two-way; reverting the PR restores latest-only behavior.

Blast Radius: medium — aggregator collection, cache files beside the feed, live source selection, and AA page/API only.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 8, 2026 07:55
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fdf787e8-c84c-4021-a19d-c3f1cb377d5a
Commits

Reviewing files that changed from the base of the PR and between ca9a495 and 29c0b34.

Files selected for processing: 9

  • pm-stack/aggregator/scripts/collect-fleet-feed.ts
  • pm-stack/aggregator/src/aa-batch-sql.ts
  • pm-stack/aggregator/src/aa-batches.ts
  • pm-stack/aggregator/src/model.ts
  • pm-stack/aggregator/src/render.ts
  • pm-stack/aggregator/src/server.ts
  • pm-stack/aggregator/src/source.ts
  • pm-stack/aggregator/src/sources/live.ts
  • pm-stack/aggregator/test/aa-batches.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-10T21:09:18.943401Z
We couldn’t complete this review. Comment @codex review to try again.
29c0b34 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 783f9aa4f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +653 to +654
const section = await assemble(await fetchAaPayload(token, ref, row.importBatch));
if (section) built++;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Count failed historical fetches toward the per-tick limit

When historical queries fail or return payloads that fail assembly, built never increments, so this loop can query every uncached historical batch rather than stopping after two attempts. Each request has a 60-second timeout, so an upstream outage can both amplify Management API pressure and substantially delay publication of the entire fleet feed. Consume the budget before each fetch, regardless of whether assembly succeeds.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 82b77ad (this branch): the per-tick budget is now consumed before each historical fetch (attempts++ ahead of the assemble call), so failed or unassemblable batches count against AA_HISTORICAL_BUILDS_PER_TICK and an upstream outage cannot turn the loop into an unbounded run of 60s queries. Verified in the current head of collect-fleet-feed.ts and by test/aa-batches.test.ts (18/18, lane code-y, task 12631).

Comment thread pm-stack/aggregator/src/sources/live.ts Outdated
Comment on lines +1703 to +1705
if (isAaBatchCacheEntry(parsed) && isAaSection(parsed.section) && parsed.section.status === "ok") {
provenance.aa = `live (fleet feed · historical batch ${batch.slice(0, 8)} · collected ${parsed.section.generatedAt})`;
return { ...parsed.section, batches: batchList };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject historical caches invalidated by a config change

After the OpenCode configuration changes, the collector marks caches with mismatched configFingerprint values as unavailable and rebuilds only two historical versions per tick. This reader nevertheless serves any structurally valid cache file, including those invalidated entries, as an ordinary successful section. Selecting a version awaiting rebuild therefore exposes the old fleet catalog and coverage without a stale warning. Honor the collector's cache-validity metadata, or explicitly mark invalidated payloads stale until they are rebuilt.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6f5a3e2 (this branch): the AA reader in src/sources/live.ts now honors the index's cache-validity flag — a batch whose cache was invalidated (cached === false) is served with stale: true and a staleReason explaining the rebuild, never as an ordinary successful section. Covered by the test "a cache invalidated by a config change is served stale, not as ordinary success" in test/aa-batches.test.ts (18/18, lane code-y, task 12631).

Comment on lines +638 to +642
await writeAaLastGood({
batch: latestSection.batch,
configFingerprint: fingerprint,
fingerprint: cacheMeta.get(latestSection.batch)?.fingerprint ?? undefined,
section: latestSection,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Persist the batch index in the last-good section

On a subsequent token, index-query, or latest-payload failure, degrade() returns lastGood.section, but this write occurs before batches is attached to the returned section. The per-batch cache also stores sections without that index, so successful collection does not normally preserve it anywhere in the last-good payload. Consequently, a transient collection failure removes the dataset selector and prevents browsing already-cached versions through the page. Persist the completed section, including its batch summaries, after constructing the index.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 82b77ad (this branch): after the batch index is attached, the collector re-writes the last-good payload with the index included (writeAaLastGood with the withIndex section), so a later transient failure degrades to a section that still carries the dataset selector and every cached version stays browsable. The per-batch cache write in assemble() is unchanged; the last-good store is now written twice per successful tick — the second write is the one that persists.

for (const row of index) {
if (built >= AA_HISTORICAL_BUILDS_PER_TICK) break;
if (row.importBatch === latestSection.batch) continue;
if (cacheMeta.get(row.importBatch)?.cached) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refresh the current-price overlay for cached historical batches

When token prices change and a newer workbook is imported, the new latest payload reads the updated v_current_prices, but previously cached historical payloads are skipped indefinitely while the OpenCode config remains unchanged. Those sections retain both their original prices and the price-derived catalog built by aaSectionFromSupabase, so switching dataset versions also switches token rates despite the page explicitly describing them as a current, non-historical overlay. Refresh the batch-independent prices and rebuild the affected catalog rates without requiring the historical measurements to be fetched again.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 62b9b69 (this branch, lane code-y / task 12631): cached AA sections are now validity-keyed on the current-price overlay as well as the config. Each cache entry records pricesFingerprint (aaPricesFingerprint — sha256 of the section's v_current_prices rows, normalized to the AaPrice field set); the collector hashes the live overlay once per tick (AA_PRICES_SQL, the payload's own prices subquery) and treats any cache whose stored fingerprint differs as invalid, so a price-only change rebuilds historical sections at the usual bounded rate instead of serving frozen prices/catalog as current. Entries written before this change carry no fingerprint and are treated as stale once. Oracle tests in test/aa-batches.test.ts: fingerprint stable across key/row order, changes when any price changes (18/18 pass).

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

repo-worker-code-k and others added 2 commits November 10, 2026 08:42
…atch index

- Consume the per-tick historical build budget before each fetch so a
  failing or unassemblable batch still counts (Codex P2 on #7564): an
  upstream outage can no longer turn the loop into unbounded 60s queries.
- Rewrite the last-good AA payload after the batch index exists, so a
  later transient failure degrades to a page that still offers every
  cached version instead of losing the dataset selector (Codex P2 on #7564).
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

…resh

A cached historical payload whose configFingerprint no longer matches the
current opencode config is marked unavailable in the index and rebuilt a
few per tick. The reader served it as an ordinary success, exposing the
old fleet catalog and coverage with no warning (Codex P2 on #7564).
Honour the index's cached flag: return the payload with stale/staleReason
so the page's existing stale banner explains the rebuild.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@dezren39

Copy link
Copy Markdown
Member Author

Review findings addressed (head 6f5a3e29)

All four Codex P2 findings from the 2026-11-08 review, in order:

  1. Count failed historical fetches toward the per-tick limit — fixed in 82b77ad3.
    The budget is now consumed (attempts++) before each fetch, so a failing or
    unassemblable batch counts against AA_HISTORICAL_BUILDS_PER_TICK. An upstream
    outage can no longer turn the loop into an unbounded run of 60 s queries.

  2. Reject historical caches invalidated by a config change — fixed in 6f5a3e29.
    The reader now honours the index's cached: false flag for the selected batch and
    returns the payload with stale: true + a staleReason explaining the rebuild, so
    the page's existing stale banner fires instead of the old catalog/coverage passing as
    ordinary success. Covered by a new test
    (a cache invalidated by a config change is served stale, not as ordinary success).

  3. Persist the batch index in the last-good section — fixed in 82b77ad3.
    writeAaLastGood is called a second time after the index is attached, so a later
    transient failure degrades to a page that still offers every cached version instead of
    silently losing the dataset selector.

  4. Refresh the current-price overlay for cached historical batches — not fixed here,
    filed as a follow-up.
    The overlay is v_current_prices, batch-independent, but the
    cached section.prices and price-derived catalog rates are frozen at build time, so
    switching versions also switches token rates while the page calls the overlay current.
    Fixing it changes the per-batch cache contract (store prices separately from the
    batch-bound payload, or re-overlay on read), which is broader than this PR's scope and
    needs its own tests. The page already states the overlay's semantics, and the pricing
    is cosmetic to the version-browsing feature this PR delivers.

Targeted verification: bun test test/aa.test.ts test/aa-batches.test.ts — 59 pass, 0 fail.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@dezren39
dezren39 merged commit 02d20c0 into main Nov 10, 2026
1 of 6 checks passed
@dezren39
dezren39 deleted the queue/12631-3302-aa-batch-versioning branch November 10, 2026 21:09
@dezren39

Copy link
Copy Markdown
Member Author

Salvage comparison — closed PR #7381 vs this merged PR (task 14093, lane code-l, 2026-11-10)

Task 14093 asked for the salvage remainder of closed PR #7381 (branch archive/janitor-2026-11-07/4924, head 592ef208df; the branch itself is deleted from origin, the head was read via refs/pull/7381/head). The prior triage had already narrowed the salvageable slice to the AA batch-history work for issue #3302 across 9 files, and marked the other 6 files obsolete stale variants.

Verdict: nothing unique — superseded by this PR. Evidence (fresh, this shift):

  • The three core AA files exist on current main, and the archive branch's versions are strict subsets of main's: git diff main..pr7381-head over src/aa-batch-sql.ts, src/aa-batches.ts, test/aa-batches.test.ts shows 0 insertions and only deletions (16 / 42 / 158 lines present on main, absent on the branch) — main carries everything the archive had, plus this PR's Codex fixes.
  • AA wiring reference counts are identical between branch and main in every remaining file (model.ts 2/2, render.ts 1/1, sources/live.ts 4/4, scripts/collect-fleet-feed.ts 23/23).
  • Issue AA explorer: dataset version switcher — browse older AA import batches, not just latest #3302 is CLOSED (completed) by this PR's merge (02d20c012d, 2026-11-10T21:09:40Z).

No re-application is needed; task 14093 completes as superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant